package com.springboot.cloud.demos.feign.rest;

import cn.jmessage.api.common.model.RegisterInfo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.aliyuncs.exceptions.ClientException;
import com.springboot.cloud.common.core.entity.vo.Result;
import com.springboot.cloud.common.core.exception.SystemErrorType;
import com.springboot.cloud.common.core.jiguang.JiGuangUtil;
import com.springboot.cloud.common.core.qcloud.QcloudUtil;
import com.springboot.cloud.common.core.sensitive.SensitiveFilter;
import com.springboot.cloud.common.core.sms.SmsUtil;
import com.springboot.cloud.common.core.util.DateUtils;
import com.springboot.cloud.common.core.util.RandomUtil;
import com.springboot.cloud.common.core.util.RsaEncrypt;
import com.springboot.cloud.common.web.entity.constant.WeixinConstant;
import com.springboot.cloud.demos.entity.enums.VipStatus;
import com.springboot.cloud.demos.entity.form.*;
import com.springboot.cloud.demos.entity.po.User;
import com.springboot.cloud.demos.entity.po.UserPosition;
import com.springboot.cloud.demos.feign.service.*;
import com.springboot.cloud.demos.feign.weixin.AES;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import javax.servlet.http.HttpServletRequest;
import java.security.AlgorithmParameters;
import java.security.Security;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;

@Slf4j
@RestController
public class UserPositonController extends BaseController {

    @Autowired
    private UserService userService;

    @Autowired
    private UserPositionService userPositionService;


    @PutMapping("/userPosition")
    public Result update(HttpServletRequest request, @RequestBody UserPositionForm userPositionForm) {
        User existUser = getUser(request);

        Result<UserPosition> result = userPositionService.query(existUser.getId());
        if (result.isSuccess()) {
            UserPosition userPosition = result.getData();
            userPositionForm.setId(userPosition.getId());
            userPositionForm.setUserId(existUser.getId());
            userPositionForm.setLoginTime(new Date());
            userPositionService.update(userPositionForm);
        }

        return Result.success(userPositionForm);
    }

    @GetMapping("/userPosition")
    public Result getUserInfo(HttpServletRequest request) {
        User user = getUser(request);
        return userPositionService.query(user.getId());
    }

}
